package com.lhn.netty.netty_demo.buf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

/**
 * betybuf
 *
 * @author lhn
 * @date 2025/06/02 17:27
 * @since 1.0.0
 **/
public class NettyBuf01 {

    public static void main(String[] args) {
        // 创建一个buf
        // 在netty中的buffer不需要使用 flip 进行反转
        // 底层维护了一个writer index 和 reader index
        ByteBuf buffer = Unpooled.buffer(10);
        while (true) {
            buffer.clear();
            for (int i = 0; i < buffer.capacity(); i++) {
                buffer.writeByte(i);
            }
            System.out.println("capacity" + buffer.capacity());
            // 读取
            for (int i = 0; i < buffer.capacity(); i++) {
                System.out.println(buffer.readByte());
            }
        }
    }

}